﻿package net.wangit.framework.action;

import net.wangit.support.Action;
import net.wangit.support.Proxy;
import net.wangit.support.action.DefaultAction;
import net.wangit.util.Checker;
import net.wangit.util.ClassUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class DefaultProxy implements Proxy {

	private static final Log log = LogFactory
			.getLog(net.wangit.framework.action.DefaultProxy.class);

	public DefaultProxy() {
	}

	public Action getAction(String className) throws Exception {
		if (Checker.isEmpty(className))
			return new DefaultAction();
		try {
			return (Action) ClassUtil.loadClass(className).newInstance();
		} catch (InstantiationException e) {
			log.error((new StringBuilder("类{")).append(className).append(
					"}不能被实例化。").toString());
			throw e;
		} catch (IllegalAccessException e) {
			log.error((new StringBuilder("类{")).append(className).append(
					"}的方法不能调用。").toString());
			throw e;
		} catch (ClassNotFoundException e) {
			log.error((new StringBuilder("类{")).append(className).append(
					"}不能找到。").toString());
			throw e;
		}
	}

}
